package com.itheima.day06JDBC连接池JDBCTemplate.Demo1.C3P0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class Demo2c3p0 {
    public static void main(String[] args) throws SQLException {
        //testName();
        //获取DataSource使用默认的<default-config>配置
        //使用默认的比较多
        DataSource ds = new ComboPooledDataSource();
        //2.获取连接(超过配置文件的连接池里面的连接数量异常)
        for (int i = 0; i < 11; i++) {
            Connection conn = ds.getConnection();
            System.out.println(conn);
            if (i == 5) {
                //归还连接
                conn.close();
            }
        }
    }

    public static void testName() throws SQLException {
        //获取DataSource,使用指定名称的配置
        DataSource ds = new ComboPooledDataSource("otherc3p0");

        //2.获取连接(超过配置文件的连接池里面的连接数量异常)
        for (int i = 0; i < 8; i++) {
            Connection conn = ds.getConnection();
            System.out.println(conn);
        }
    }
}
